<template>
  <el-card>
    <div class="CHHeader">
      <el-form :model="CHHeaderForm" ref="CHHeaderForm" @submit.prevent>
        <span
          style="
            font-size: 20px;
            font-weight: 600;
            height: 7vh;
            line-height: 7vh;
            margin-left: 50px;
          "
          >医务室病历管理</span
        >
        <el-row
          :gutter="28"
          style="width: 50vw; padding-top: 9px; height: 7vh; float: right"
        >
          <el-col :span="8">
            <el-form-item style="float: right">
              <span style="font-size: 18px">&nbsp;</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item prop="drugname">
              <el-input
                placeholder="输入患者名称"
                @change="SelectCaseHistories"
                v-model="CHHeaderForm.chname"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="2">
            <el-form-item>
              <el-button type="success" @click="SelectCaseHistories"
                >查询</el-button
              >
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="CHContent">
      <el-table
        :data="
          CaseHistoriesList.slice(
            (currentPage - 1) * pageSize,
            currentPage * pageSize
          )
        "
        border
        id="#eltable"
        height="61vh"
        :header-cell-style="{ 'text-align': 'center', 'font-size': '14px' }"
        :cell-style="{ 'text-align': 'center' }"
      >
        <el-table-column prop="cid" fixed label="病历编号" />
        <el-table-column prop="cname" fixed label="患者姓名" />
        <el-table-column prop="sex" fixed label="性别">
          <template #default="props">
            {{ props.row.sex == 1 ? "男" : "女" }}
          </template>
        </el-table-column>
        <el-table-column prop="vresult" fixed label="诊断结果"  show-overflow-tooltip/>
        <el-table-column prop="vtime" fixed label="就诊时间" />
        <el-table-column prop="telephone" fixed label="联系电话" />
        <el-table-column prop="name" label="操作" width="200">
          <template #default="scope">
            <el-button
              size="small"
              link type="primary"
              @click="MCaseHistoryDetails(scope.row.cid)"
              >详情</el-button
            >
            <el-button
              size="small"
              link type="primary"
              @click="MCaseHistoriesList(scope.row.cid)"
              >列表</el-button
            >
          </template>
        </el-table-column>
        <template v-slot:empty>
          <span style="color: #969799">未查询到患者信息</span>
        </template>
      </el-table>
      <div class="page">
        <el-pagination
          v-model:current-page="currentPage"
          :page-size="pageSize"
          layout="total, prev, pager, next"
          background
          :total="CaseHistoriesList.length"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
  </el-card>
</template>

<script>
import {
  queryCaseHistoriesList,
  QueryPatientByIdCard,
} from "@/api/caseHistory";
import { pageMixin } from "@/mixins/pageMixin";
export default {
  mixins: [pageMixin],
  data() {
    return {
      CHHeaderForm: {
        chname: "",
      },
      CaseHistoriesList: [],
      FindCaseHistory: [],
    };
  },
  created() {
    this.fetchCaseHistory();
  },
  methods: {
    Find(id) {
      for (var i = 0; i < this.CaseHistoriesList.length; i++) {
        if (id == this.CaseHistoriesList[i].cid) {
          this.FindCaseHistory = this.CaseHistoriesList[i];
          break;
        }
      }
    },
    MCaseHistoryDetails(params) {
      this.$router.push(`/caseHistory/details?param=${params}`);
    },
    MCaseHistoriesList(cid) {
      this.Find(cid);
      QueryPatientByIdCard(this.FindCaseHistory.idcard).then((res) => {
        this.CaseHistoriesList = res.data.data;
      });
    },
    fetchCaseHistory() {
      queryCaseHistoriesList().then((res) => {
        this.CaseHistoriesList = res.data.data;
      });
    },
    SelectCaseHistories() {
      QueryPatientByIdCard(this.CHHeaderForm.chname).then((res) => {
        this.CaseHistoriesList = res.data.data;
      });
    },
  },
};
</script>

<style>
.CHHeader {
  width: 100%;
  height: 7vh;
  margin-bottom: 5px;
}

.CHContent {
  width: 100%;
  height: 67vh;
}

.page {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-right: 20px;
  align-items: end;
  width: 100%;
  height: 40px;
  background-color: white;
}

.el-form-item__label {
  width: 125px !important;
}
#eltable {
  width: 100% !important;
}
</style>
: any(: { data: { data: any } })(: any)(: any)
